/**
 * 渠道推广
 *
 * @author linfeng
 * @since 2019/10/23
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var layedit = layui.layedit;
    var laydate = layui.laydate;

    form.render(null, "zmn-form");

    zmnLayUtil.layFormVerify(form);

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var openId = layer.open({type: 3});
        var data = obj.field;
        var url = "/channel/promotion/addEdit.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(result) {
                layer.close(openId);
                if(result.status == 200) {
                    layer.msg(result.message);
                    zmnPage.direct("/channel/promotion/detail.action?relateId="+result.data, 100);
                } else {
                    layer.msg(result.message, {icon: 2})
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                layer.close(openId);
            }
        })

        return false;
    });

    //点击取消
    $(document).on('click', '#cancel', function () {
        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    });


    //对外暴露的接口
    exports('channel_promotion_edit', {});
});